export default class Handler<Func extends Function> {
    static pool: Handler<any>[] = []
    func: Func
    caller: any
    private constructor() { }

    static create<Func extends Function>(caller: any, func: Func) {
        let ins = Handler.pool.pop() || new Handler<Func>()
        ins.caller = caller
        ins.func = func
        return this
    }

    run(...parms: any[]) {
        this.func.call(this.caller, ...parms)
    }

    recy() {
        this.func = null
        this.caller = null
        Handler.pool.push(this)
    }
}